/**
 * Independent time operation tool to facilitate subsequent switch to dayjs
 */
import dayjs from 'dayjs';
import { time } from 'echarts';

const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
const DATE_FORMAT = 'YYYY-MM-DD';
const TIME_FORMAT = 'HH:mm:ss';

export function formatToDateTime(date: dayjs.Dayjs | undefined = undefined, format = DATE_TIME_FORMAT): string {
  return dayjs(date).format(format);
}

export function formatToDate(date: dayjs.Dayjs | undefined = undefined, format = DATE_FORMAT): string {
  return dayjs(date).format(format);
}
export function getCurrentData() {
  const date = new Date();
  const day = dayjs(date).day();
  let dayString = '';
  switch (day) {
    case 0:
      dayString = '星期天';
      break;
    case 1:
      dayString = '星期一';
      break;
    case 2:
      dayString = '星期二';
      break;
    case 3:
      dayString = '星期三';
      break;
    case 4:
      dayString = '星期四';
      break;
    case 5:
      dayString = '星期五';
      break;
    case 6:
      dayString = '星期六';
      break;
    default:
      dayString = '';
  }
  const newdate = dayjs(date).format(DATE_FORMAT);
  const newTime = dayjs(date).format(TIME_FORMAT);
  return {
    date: newdate,
    week: dayString,
    time: newTime,
  };
}

export const dateUtil = dayjs;
